<template>
    <div v-cloak class='app_container'>
        <!-- header -->
        <mt-header fixed title="vue项目">
            <mt-button v-if='back' slot="left" icon="back" @click='historyBack'>返回</mt-button>
        </mt-header>
        <!-- 内容 -->
        <transition class="app_content" tag='div' @before-enter="before" @enter="enter" @leave="leave" mode='out-in'>
            <router-view></router-view>
        </transition>
        <!-- tabbar -->
        <nav class="mui-bar mui-bar-tab">
			<router-link class="mui-tab-item2" :to="tabbarRoute.home">
				<span class="mui-icon mui-icon-home"></span>
				<span class="mui-tab-label">首页</span>
			</router-link>
			<router-link class="mui-tab-item2" to="/member">
				<span class="mui-icon mui-icon-contact"><span class="mui-badge">0</span></span>
				<span class="mui-tab-label">消息</span>
			</router-link>
			<router-link class="mui-tab-item2" to="/cart">
				<span class="mui-icon mui-icon-extra mui-icon-extra-cart"><span class="mui-badge">0</span></span>
				<span class="mui-tab-label">购物车</span>
			</router-link>
			<router-link class="mui-tab-item2" to="/center">
				<span class="mui-icon mui-icon-gear"></span>
				<span class="mui-tab-label">设置</span>
			</router-link>
		</nav>
    </div>
</template>

<script>
    
    export default {
        data() {
            return {
                tabbarRoute: {
                    home: '/home'
                },
                back: false
            }
        },
        methods: {
            before(el,done) {
                console.log(el.offsetWidth)
                el.style.opacity = 0;
                el.style.transform = `translateX(${el.offsetWidth}px)`; 
            },
            enter(el,done) {
                el.offsetWidth;
                el.style.opacity = 1;
                el.style.transform = "translateX(0)";
                el.style.transition = "all ease .8s";
                done();
            },
            leave(el,done) {
                el.style.opacity = 0;
                el.style.transform = `translateX(-${el.offsetWidth}px)`;
                el.style.transition = "all ease .8s";
                done();
            },
            historyBack() {
                this.$router.back();
            }
        },
        created() {
            this.back = this.$route.path == '/home' ? false : true;1
        },
        
        watch: {
            '$route'(to, from) {
                if(to.path != '/home') {
                    this.back = true;
                } else {
                    this.back = false;
                }
            }
        }
    }
</script>

<style lang='scss'>
[v-cloak] {
  display: none;
}
* {
  touch-action: pan-y;
}
.app_container {
  padding-top: 41px;
  padding-bottom: 50px;
  width: 100%;
  // 只能overflow-x 限制宽度溢出隐藏
  overflow-x: hidden;
  .mint-header {
    background-color: #f7f7f7;
    box-shadow: 0 1px 6px #ccc;
    .mint-header-title {
      color: #000;
    }
    .mint-button {
      color: #000;
    }
  }
  .mui-bar {
    box-shadow: 0 0 1px rgba(0, 0, 0, 0.3);
  }
  .mui-bar-tab .mui-tab-item2.mui-active {
    color: #007aff;
  }
  .mui-bar-tab .mui-tab-item2 {
    display: table-cell;
    overflow: hidden;
    width: 1%;
    height: 50px;
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: #929292;
  }
  .mui-bar-tab .mui-tab-item2 .mui-icon {
    top: 3px;
    width: 24px;
    height: 24px;
    padding-top: 0;
    padding-bottom: 0;
  }
  .mui-bar-tab .mui-tab-item2 .mui-icon ~ .mui-tab-label {
    font-size: 11px;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
</style>